package com.zhanbo.zhanbowymusic.main.mine.recently.adapter;

import android.content.Context;
import android.view.View;

import com.mwx.baselib.base.BaseBindingAdapter;
import com.mwx.baselib.bean.SongBean;
import com.mwx.baselib.net.LikeMusic;
import com.mwx.baselib.utils.GlideUtils;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.databinding.ItemRecentlySingleSongBinding;

public class SingleSongListAdapter extends BaseBindingAdapter<SongBean, ItemRecentlySingleSongBinding> {

    public SingleSongListAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_recently_single_song;
    }

    @Override
    protected void onBindItem(ItemRecentlySingleSongBinding binding, SongBean item) {
        if (item.getIsLike()==1){
            binding.ivIsLike.setImageResource(R.mipmap.like);
        }else {
            binding.ivIsLike.setImageResource(R.mipmap.like_no);
        }
        binding.ivIsLike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setIsLike(item.getIsLike()==1?0:1);
                LikeMusic.like(context,item.getId()+"");
                notifyDataSetChanged();
            }
        });
        GlideUtils.loadImageRounded10(context,item.getCoverImg(),binding.ivLikeListItemIcon);
        binding.tvLikeListItemSong.setText(item.getName()+"");
        binding.tvSingerName.setText(item.getArtistName()+"");
        binding.tvLikeListItemNum.setText("0"+(getPosition()+1));
        binding.tvAlbumName.setText(item.getAlbumName()+"");
        binding.tvTime.setText(String.valueOf(item.getDuration()).replace(".",":"));
    }
}
